package com.builder.inputeditor.fieldtypefields;

import com.builder.inputeditor.InputFieldPanel;
import java.awt.Dimension;
import java.util.List;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 * @author Dmitry
 */
public class TimestampFieldParams extends AbstractFieldParams {
    private JTextField patternField;

    public TimestampFieldParams() {
        super("timestamp");
    }

    @Override
    public void serialize() {

    }

    @Override
    public void deserialize() {

    }

    private String tryToSearchLastPattern(List<InputFieldPanel> fields) {
        for (InputFieldPanel panel : fields) {
            if (parent != panel && panel.getFieldParams() instanceof TimestampFieldParams) {
                return ((TimestampFieldParams) panel.getFieldParams()).patternField.getText();
            }
        }
        return "ddMMYYYY";
    }

    @Override
    public void init(JPanel holder, List<InputFieldPanel> fields) {
        holder.removeAll();
        holder.add(new JLabel("Pattern"));

        patternField = new JTextField();
        patternField.setPreferredSize(new Dimension(100, 20));
        patternField.setText(tryToSearchLastPattern(fields));
        holder.add(patternField);
    }

}
